﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;
using Entity;
using Common;

namespace DataAccess
{
    public class ClassDA
    {
        public static List<Classs> generateClass(Branch branch)
        {
            List<Classs> Classes = null;
            using (SqlConnection conn = ConnectData.getConnection())
            {
                try
                {
                    conn.Open();
                    SqlCommand cm = new SqlCommand("Get_Classes", conn);
                    cm.CommandType = CommandType.StoredProcedure;
                    cm.Parameters.Add("@BranchID", SqlDbType.Int);
                    cm.Parameters["@BranchID"].Value = branch.BranchID;
                    SqlDataAdapter da = new SqlDataAdapter(cm);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    Classes = LibConvert.ConvertTo<Classs>(ds.Tables[0]);
                    //SqlDataReader dr = cm.ExecuteReader();
                    //Classes = new List<Classs>();
                    //while (dr.Read())
                    //{
                    //    Classs cl = new Classs { ClassID = dr.GetInt32(0), ClassName = dr.GetString(1), FacultyID = dr.GetInt32(2), BranchID = dr.GetInt32(3), TimeSlot = dr.GetString(4), StartDay = dr.GetDateTime(5), EndDay = dr.GetDateTime(6), ClassStatus = dr.GetBoolean(7).ToString() };
                    //    Classes.Add(cl);
                    //}
                    
                    conn.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("error class");
                }
            }
            return Classes;
        }
    }
}
